﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

using BMS.Models;
using BMS.Utilities;

namespace BMS.Models.DataAccess
{
    public class UserAccountRepository
    {
        private DatabaseAccess db = new DatabaseAccess();

        public List<UserAccountModel> GetAllUsersAccounts()
        {
            List<UserAccountModel> allUserList = new List<UserAccountModel>();
            String query = "SELECT * FROM " + Configuration.DatabaseName + ".user";

            db.DBConnectionOn();

            try
            {
                MySqlCommand cmd = new MySqlCommand(query, db.connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    UserAccountModel user = new UserAccountModel();

                    user.UserName = dataReader["vc_fldUserName"] + "";
                    user.UserPassword = dataReader["vc_fldPassword"] + "";
                    user.UserType = dataReader["vc_fldUserType"] + "";
                    user.UserCreateDate = (DateTime)dataReader["dt_fldCreate"];

                    allUserList.Add(user);
                }
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                db.DBConnectionOff();
            }
            return allUserList;
        }
    }
}